package com.sfzd5.noipinfo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.gson.Gson;

public class SubmissionActivity extends AppCompatActivity {

    ProgressBar progressBar;
    ExpandableListView elv;
    SubmissionResult result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_submission);

        setTitle("完成作业");

        int userId = getIntent().getIntExtra("userId", 0);

        progressBar = findViewById(R.id.progressBar);
        elv = findViewById(R.id.elv);

        progressBar.setVisibility(View.VISIBLE);

        HttpHelper httpHelper = new HttpHelper();
        httpHelper.asyncGetJson("http://ai.sfzd5.com:8800/getusersubmission/?id=" + String.valueOf(userId), new HttpJsonResult() {
            @Override
            public void tackJson(String json) {
                runOnUiThread(new Runnable() {
                    public void run() {
                        progressBar.setVisibility(View.GONE);
                        if(json == null || json == ""){
                            Toast.makeText(SubmissionActivity.this,"下载信息失败", Toast.LENGTH_LONG).show();
                            return;
                        }
                        result = new Gson().fromJson(json, SubmissionResult.class);
                        SubmissionExpandableListAdapter adapter = new SubmissionExpandableListAdapter(SubmissionActivity.this, result);
                        elv.setAdapter(adapter);

                        for(int i=0; i<result.data.size(); i++)
                            elv.expandGroup(i);
                    }
                });
            }
        });
    }
}